package com.enjoyor.health.HGPT.web.rest;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import com.enjoyor.health.HGPT.core.config.ParamConfig;
import com.enjoyor.health.HGPT.web.CodeEnum;
import com.enjoyor.health.HGPT.web.RetResult;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Zhu Min
 * @date 2023/12/28 13:54
 */
@Slf4j
@Api(value = "开放接口", tags = {"开放接口"})
@CrossOrigin
@RequestMapping("/open")
@RestController
public class OpenController {

    @Autowired
    private ParamConfig paramConfig;

    @RequestMapping(value = "/aiHealthReport/dataBoard", method = { RequestMethod.GET, RequestMethod.POST })
    public RetResult getDataBoard(){
        String url = paramConfig.getDataBoard();
        String data = HttpUtil.get(url, 15000);
        if (StringUtils.isNotBlank(data)){
            return JSON.parseObject(data, RetResult.class);
        }else {
            return new RetResult(CodeEnum.SERVER_EXCEPTION);
        }

    }

}
